package org.kazuhiko.rpg.server.task.tasks;

import org.apache.mina.core.session.IoSession;
import org.kazuhiko.rpg.server.Server;
import org.kazuhiko.rpg.server.net.RPGSession;
import org.kazuhiko.rpg.server.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class SessionClosedTask implements Task
{
	private static final Logger logger = LoggerFactory.getLogger( SessionClosedTask.class );
	
	private final IoSession session;
	
	public SessionClosedTask( IoSession session )
	{
		this.session = session;
	}
	
	@Override
	public void execute()
	{
		logger.info( "Session with {} closed.", session.getRemoteAddress() );
		Server.getServer().unregister( ( ( RPGSession ) session.getAttribute( "attachment" ) ) );
		session.removeAttribute( "attachment" );
	}
}